﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ATA.Business;
using ATA.Data;
using ATA.Entities;
using Infragistics.Win.UltraWinEditors;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win;
using ATA.Winforms;
namespace ATA.Winforms
{
    public partial class formSearchRevenue : Form
    {

        public formSearchRevenue()
            {
                InitializeComponent();
            }
            private Guid _CustomerID = Guid.Empty;
            private int _RevenueId = 0;
            public Guid CustomerID
            {
                get
                {
                    return _CustomerID;
                }
                set
                {
                    _CustomerID = value;
                }
            }
            private DataSet dsRevenue = new DataSet("Revenue");
            private VList<VwInventoryItem> vLisHangHoa = new VList<VwInventoryItem>();

            private void formSearchRevenue_Load(object sender, EventArgs e)
            {
                SettingKhachHang();
                LoadHangHoa();
                loadDataGrid(CustomerID);

            }
            private void SettingKhachHang()
            {
                DropDownEditorButton objKhachHang = new DropDownEditorButton();
                objKhachHang.Control = this.grdKhachHang;
                txtkhachhang.ButtonsRight.Add(objKhachHang);
                txtkhachhang.ReadOnly = true;
                txtkhachhang.Anchor = AnchorStyles.Right;
                grdKhachHang.DataSource = LoadKhachHang();
                grdKhachHang.UseFlatMode = DefaultableBoolean.True;

            }
            private TList<KhachHang> LoadKhachHang()
            {
                KhachHangService khservice = new KhachHangService();

                if (Globals.gv_bIsGlobalBranch)
                {
                    return khservice.GetAll();
                }
                else
                {
                    return khservice.GetAllByBrand(Globals.gv_strBranchID);
                }
            }
            private void LoadHangHoa()
            {
                //    VwInventoryItemService hhservice = new VwInventoryItemService();
                //    VList<VwInventoryItem> listhanghoa = hhservice.GetAll();
                //    cboHangHoa.DataSource = listhanghoa;
                //    cboHangHoa.DataBind();
            }
            private void loadDataGrid(Guid khID)
            {
                RevenueService dsService = new RevenueService();
                //TList<Revenue> listds = dsService.GetByCustomerId(khID);
                TList<Revenue> listds = dsService.GetAllRevenues(khID, txthoadon.Text , Convert.ToInt16(cboYear.Value), Convert.ToInt16(cboMonth.Value));
                //TList<Revenue> listdsNew = listds.FindAll("OrderNum", OrderNum);
                if (listds != null)
                {
                    dsRevenue = listds.ToDataSet(false);
                    ultraGrid1.DataSource = dsRevenue;
                    ultraGrid1.DataBind();
                    loadTongCong(listds);
                }


            }
            private void loadTongCong(TList<Revenue> list)
            {
                decimal doanhthu = 0;
                foreach (Revenue ds in list)
                {
                    doanhthu += (decimal)ds.Popular + (decimal)ds.Deluxe;
                }
                txtTong.Value = doanhthu;
            }

            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                ultraGrid1.DisplayLayout.Bands[0].AddButtonCaption = "Doanh Số";
                ultraGrid1.DisplayLayout.Appearance.FontData.SizeInPoints = 8;
                ultraGrid1.DisplayLayout.TabNavigation = TabNavigation.NextCell;
                ultraGrid1.DisplayLayout.ViewStyleBand = ViewStyleBand.Vertical;
                ultraGrid1.DisplayLayout.GroupByBox.Style = GroupByBoxStyle.Compact;
                ultraGrid1.DisplayLayout.GroupByBox.BorderStyle = UIElementBorderStyle.InsetSoft;
                ultraGrid1.DisplayLayout.GroupByBox.ButtonBorderStyle = UIElementBorderStyle.RaisedSoft;
                ultraGrid1.DisplayLayout.GroupByBox.BandLabelBorderStyle = UIElementBorderStyle.Solid;
                ultraGrid1.DisplayLayout.GroupByBox.ButtonConnectorStyle = UIElementBorderStyle.Dotted;
                ultraGrid1.DisplayLayout.GroupByBox.ButtonConnectorColor = Color.Maroon;
                ultraGrid1.DisplayLayout.UseFixedHeaders = true;
                ultraGrid1.DisplayLayout.AddNewBox.Hidden = true;
                //ultraGrid1.DisplayLayout.AddNewBox.Prompt = "Thêm mới";
                //ultraGrid1.DisplayLayout.AddNewBox.Style = AddNewBoxStyle.Full;
                //ultraGrid1.DisplayLayout.AddNewBox.ButtonStyle = UIElementButtonStyle.WindowsVistaButton;

                foreach (UltraGridBand b in ultraGrid1.DisplayLayout.Bands)
                {
                    //b.AddButtonCaption = _Business_Object
                    b.Layout.Override.RowSizing = RowSizing.AutoFree;
                    b.Layout.Override.CellMultiLine = DefaultableBoolean.True;
                    b.Override.AllowAddNew = AllowAddNew.Yes;
                    b.Override.AllowDelete = DefaultableBoolean.True;
                    b.Override.ReadOnlyCellAppearance.BackColor = Color.AliceBlue;
                    b.Override.HeaderStyle = HeaderStyle.XPThemed;
                    b.Override.WrapHeaderText = DefaultableBoolean.True;
                    b.Override.SummaryFooterCaptionVisible = DefaultableBoolean.False;
                    foreach (UltraGridColumn c in b.Columns)
                    {
                        c.Header.Fixed = true;
                        c.Header.Appearance.TextHAlign = HAlign.Center;
                        if (c.DataType.Name == "DateTime")
                        {
                            c.CellAppearance.TextHAlign = HAlign.Right;
                            c.Width = 75;
                            c.Format = "d MMM yy";
                            c.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Date;
                            c.CellActivation = Activation.AllowEdit;
                        }
                        if (c.DataType.Name == "Boolean")
                        {
                            c.Width = 50;
                            c.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
                        }
                        if (c.DataType.Name == "Decimal")
                        {
                            c.CellAppearance.TextHAlign = HAlign.Right;
                            c.Width = 70;
                            c.Format = "#,##0.00";
                        }
                        if (c.DataType.Name == "String")
                        {
                            c.Nullable = Infragistics.Win.UltraWinGrid.Nullable.EmptyString;
                        }

                        c.Header.Appearance.FontData.SizeInPoints = 8;
                        c.Header.Appearance.FontData.Bold = DefaultableBoolean.True;
                    }
                }
                UltraGridBand band = ultraGrid1.DisplayLayout.Bands[0];
                if (band != null)
                {
                    band.Override.HeaderPlacement = HeaderPlacement.FixedOnTop;
                    band.Columns["ID"].Hidden = true;
                    //band.Columns["OrderNum"].Header.Caption = "SỐ HÓA ĐƠN, CHỨNG TỪ";
                    band.Columns["OrderNum"].Hidden = false;
                    band.Columns["OrderNum"].CellActivation = Activation.AllowEdit;
                    band.Columns["OrderNum"].Header.Caption = "Số Hóa Đơn";
                    band.Columns["OrderNum"].Width = 150;
                    //band.Columns["InventoryItemID"].Header.Caption = "Hàng Hóa";
                    //band.Columns["InventoryItemID"].Hidden = true;
                    //band.Columns["InventoryItemID"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
                    //band.Columns["InventoryItemID"].ValueList = cboHangHoa;
                    band.Columns["Deluxe"].Header.Caption = "CC";
                    band.Columns["Deluxe"].Width = 100;
                    band.Columns["Deluxe"].CellActivation = Activation.AllowEdit;
                    band.Columns["Popular"].Header.Caption = "TD";
                    band.Columns["Popular"].Width = 100;
                    band.Columns["Popular"].CellActivation = Activation.AllowEdit;
                    band.Columns["CustomerID"].Hidden = true;
                    //band.Columns["OrderDate"].Index = 0;
                    //band.Columns["Popular"].Header.Caption = "Thành Tiền";
                    //band.Columns["Revenue"].Index = 1;
                    //band.Columns["Popular"].Width = 100;
                    //band.Columns["Popular"].CellActivation = Activation.AllowEdit;
                    band.Columns["Note"].Header.Caption = "Ghi Chú";
                    //band.Columns["Note"].Index = 3;
                    band.Columns["Note"].Width = 250;
                    band.Columns["Note"].CellActivation = Activation.AllowEdit;
                    band.Columns["OrderDate"].Header.Caption = "Ngày Lấy Hàng";
                    band.Columns["OrderDate"].Width = 100;
                    band.Columns["OrderDate"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Date;
                    band.Columns["OrderDate"].CellActivation = Activation.AllowEdit;
                    band.Columns["Year"].Header.Caption = "Năm";
                    band.Columns["Month"].Header.Caption = "Tháng";
                    //band.Columns["Year"].Hidden = true;
                    //band.Columns["Month"].Hidden = true;
                }

            }

            private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
            {
                _RevenueId = -1;
                foreach (UltraGridCell c in e.Row.Cells)
                {
                    if (c.Column.Key.Equals("ID"))
                    {
                        c.Value = _RevenueId;
                    }
                    else if (c.Column.Key.Equals("OrderNum"))
                    {
                        c.Value = string.Empty;
                    }
                    else if (c.Column.Key.Equals("CustomerID"))
                    {
                        c.Value = CustomerID;
                    }
                    else if (c.Column.Key.Equals("OrderDate"))
                    {
                        c.Value = DateTime.Now;
                    }
                    else if (c.Column.Key.Equals("Popular"))
                    {
                        c.Value = 0;
                    }
                    else if (c.Column.Key.Equals("Deluxe"))
                    {
                        c.Value = 0;
                    }
                    //else if (c.Column.Key.Equals("Don_Gia"))
                    //{
                    //    c.Value = 0;
                    //}
                    else if (c.Column.Key.Equals("Note"))
                    {
                        c.Value = string.Empty;
                    }
                }


            }

            private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
            {
                switch (e.Tool.Key)
                {
                    case "Search":
                        //FormSearchRevenue frm = new FormSearchRevenue();
                        //frm.Show();
                        break;
                    case "Save":
                        ultraGrid1.UpdateData();
                        DataTable dt = new DataTable();
                        if (dsRevenue != null)
                        {
                            dt = dsRevenue.Tables[0].GetChanges();
                            if (dt != null)
                            {
                                foreach (DataRow dr in dt.Rows)
                                {
                                    Revenue Revenue = new Revenue();
                                    //if (dr["OrderDate"] != null)
                                    //    Revenue.OrderDate = (DateTime)dtngaycap.Value;
                                    //Revenue.Popular = (decimal)dr["Popular"];
                                    Revenue.Year = (short)cboYear.Value;
                                    Revenue.Month = (short)cboMonth.Value;

                                    if (dr["OrderNum"] != null)
                                        Revenue.OrderNum = dr["OrderNum"].ToString();
                                    Revenue.CustomerId = CustomerID;
                                    if (dr["Note"] != null)
                                        Revenue.Note = dr["Note"].ToString();
                                    if (dr["ID"] != null & dr["ID"].ToString() != string.Empty)
                                        Revenue.Id = (int)dr["ID"];
                                    if (dr["Deluxe"] != null & dr["Deluxe"].ToString() != string.Empty)
                                        Revenue.Deluxe = (decimal)dr["Deluxe"];
                                    //if (dr["CustomerID"] != null & dr["DonGia"].ToString() != string.Empty)
                                    Revenue.CustomerId = CustomerID;
                                    if (dr["Popular"] != null & dr["Popular"].ToString() != string.Empty)
                                        Revenue.Popular = (decimal)dr["Popular"];
                                    if (dr["OrderDate"] != null & dr["OrderDate"].ToString() != string.Empty)
                                        Revenue.OrderDate = (DateTime)dr["OrderDate"];
                                    UpdateRevenue(Revenue);
                                }
                                loadDataGrid(CustomerID);
                            }

                        }
                        break;
                    case "AddNew":
                        reFreshForm();
                        break;
                    default:
                        Console.WriteLine("I'm sorry, I don't understand that!");
                        break;

                }

            }
            private void reFreshForm()
            {
                //txtOrderNum.Text = string.Empty;
                txtkhachhang.Text = string.Empty;
                //txtdiachi.Text = string.Empty;
                //txtmaso.Text = string.Empty;
                txtTong.Value = null;
                CustomerID = Guid.Empty;
                loadDataGrid(Guid.Empty);
            }
            private void grdKhachHang_InitializeLayout(object sender, InitializeLayoutEventArgs e)
            {
                grdKhachHang.DisplayLayout.Appearance.FontData.SizeInPoints = 8;
                grdKhachHang.DisplayLayout.TabNavigation = TabNavigation.NextCell;
                grdKhachHang.DisplayLayout.ViewStyleBand = ViewStyleBand.Vertical;
                grdKhachHang.DisplayLayout.GroupByBox.Style = GroupByBoxStyle.Compact;
                grdKhachHang.DisplayLayout.GroupByBox.BorderStyle = UIElementBorderStyle.InsetSoft;
                grdKhachHang.DisplayLayout.GroupByBox.ButtonBorderStyle = UIElementBorderStyle.RaisedSoft;
                grdKhachHang.DisplayLayout.GroupByBox.BandLabelBorderStyle = UIElementBorderStyle.Solid;
                grdKhachHang.DisplayLayout.GroupByBox.ButtonConnectorStyle = UIElementBorderStyle.Dotted;
                grdKhachHang.DisplayLayout.GroupByBox.ButtonConnectorColor = Color.Maroon;
                grdKhachHang.DisplayLayout.UseFixedHeaders = true;
                grdKhachHang.DisplayLayout.AddNewBox.Hidden = true;
                foreach (UltraGridBand b in grdKhachHang.DisplayLayout.Bands)
                {
                    //b.Layout.Override.RowSizing = RowSizing.AutoFree;
                    //b.Layout.Override.CellMultiLine = DefaultableBoolean.True;
                    //b.Override.AllowAddNew = AllowAddNew.No;
                    //b.Override.AllowDelete = DefaultableBoolean.False;
                    //b.Override.ReadOnlyCellAppearance.BackColor = Color.AliceBlue;
                    //b.Override.HeaderStyle = HeaderStyle.XPThemed;
                    //b.Override.WrapHeaderText = DefaultableBoolean.True;
                    //b.Override.SummaryFooterCaptionVisible = DefaultableBoolean.False;
                    foreach (UltraGridColumn c in b.Columns)
                    {
                        c.Header.Fixed = true;
                        c.Header.Appearance.TextHAlign = HAlign.Center;
                        if (c.DataType.Name == "DateTime")
                        {
                            c.CellAppearance.TextHAlign = HAlign.Right;
                            c.Width = 75;
                            c.Format = "d MMM yy";
                            c.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Date;
                            c.CellActivation = Activation.AllowEdit;
                        }
                        if (c.DataType.Name == "Boolean")
                        {
                            c.Width = 50;
                            c.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
                        }
                        if (c.DataType.Name == "Decimal")
                        {
                            c.CellAppearance.TextHAlign = HAlign.Right;
                            c.Width = 70;
                            c.Format = "#,##0";
                        }
                        if (c.DataType.Name == "String")
                        {
                            c.Nullable = Infragistics.Win.UltraWinGrid.Nullable.EmptyString;
                        }

                        c.Header.Appearance.FontData.SizeInPoints = 8;
                        c.Header.Appearance.FontData.Bold = DefaultableBoolean.True;
                    }
                }

                //grdKhachHang.DisplayLayout.Override.AllowColSizing = AllowColSizing.Free;
                //grdKhachHang.DisplayLayout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.ColumnChooserButton;
                grdKhachHang.DisplayLayout.Override.RowSelectors = DefaultableBoolean.True;
                grdKhachHang.DisplayLayout.Override.FixedCellSeparatorColor = Color.Red;
                grdKhachHang.DisplayLayout.Override.FixedHeaderIndicator = FixedHeaderIndicator.Button;
                //grdKhachHang.DisplayLayout.Override.GroupByRowInitialExpansionState = GroupByRowInitialExpansionState.Expanded;
                grdKhachHang.DisplayLayout.Override.GroupByColumnsHidden = DefaultableBoolean.False;
                grdKhachHang.DisplayLayout.Override.AllowMultiCellOperations = AllowMultiCellOperation.All;
                //grdKhachHang.DisplayLayout.Override.AllowRowSummaries = AllowRowSummaries.True;
                grdKhachHang.DisplayLayout.Override.FixedRowSortOrder = FixedRowSortOrder.FixOrder;
                grdKhachHang.DisplayLayout.Override.RowSelectorNumberStyle = RowSelectorNumberStyle.VisibleIndex;
                //grdKhachHang.DisplayLayout.Override.HeaderPlacement = HeaderPlacement.FixedOnTop;
                grdKhachHang.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.True;
                grdKhachHang.DisplayLayout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
                grdKhachHang.DisplayLayout.Override.AllowGroupBy = DefaultableBoolean.False;
                grdKhachHang.DisplayLayout.Override.GroupByColumnsHidden = DefaultableBoolean.True;
                grdKhachHang.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow;

                //grdKhachHang.DisplayLayout.UseFixedHeaders = true;
                UltraGridBand band = grdKhachHang.DisplayLayout.Bands[0];
                //band.Override.HeaderPlacement = HeaderPlacement.FixedOnTop;
                band.Columns["KhachHangID"].Hidden = true;
                band.Columns["TenKH"].Header.Caption = "Tên KH";
                band.Columns["TenKH"].Width = 150;
                band.Columns["TenKH"].CellActivation = Activation.NoEdit;
                band.Columns["GioiTinh"].Header.Caption = "Giới Tính";
                band.Columns["GioiTinh"].Width = 20;
                band.Columns["GioiTinh"].CellActivation = Activation.NoEdit;
                band.Columns["MaKH"].Header.Caption = "Mã KH";
                band.Columns["MaKH"].Width = 20;
                band.Columns["MaKH"].CellActivation = Activation.NoEdit;
                //band.Columns["MaSoHV"].Header.Caption = "Mã Hội Viên";
                //band.Columns["MaSoHV"].Width = 50;
                //band.Columns["MaSoHV"].CellActivation = Activation.NoEdit;
                band.Columns["DiaChiCty"].Header.Caption = "Địa Chỉ Công Ty";
                band.Columns["DiaChiCty"].Width = 200;
                band.Columns["DiaChiCty"].CellActivation = Activation.NoEdit;
                band.Columns["NgaySinh"].Hidden = true;
                band.Columns["LoaiKH"].Hidden = true;
                band.Columns["CMND"].Hidden = true;
                band.Columns["NgayCap"].Hidden = true;
                band.Columns["NoiCap"].Hidden = true;
                band.Columns["SoDTDK"].Hidden = true;
                band.Columns["SoDTCTY"].Hidden = true;
                band.Columns["FAX"].Hidden = true;
                band.Columns["SoGPDKKD"].Hidden = true;
                band.Columns["DiaChiTT"].Hidden = true;
                band.Columns["HoKhauTT"].Hidden = true;
                band.Columns["ParentID"].Hidden = true;

                //band.Columns["DaiLyID"].Hidden = true;
                //band.Columns["LoaiHoiVien"].Hidden = true;
                //band.Columns["NgayDangKy"].Hidden = true;


            }

            private void grdKhachHang_DoubleClick(object sender, EventArgs e)
            {
                txtkhachhang.Focus();
            }

            private void txtkhachhang_AfterEditorButtonCloseUp(object sender, EditorButtonEventArgs e)
            {
                if (grdKhachHang.ActiveRow.Index > -1)
                {
                    if (grdKhachHang.ActiveRow.Cells["KhachHangID"].Value != null)
                    {
                        CustomerID = (Guid)grdKhachHang.ActiveRow.Cells["KhachHangID"].Value;
                    }

                    setFormKhachHang(getKhachHangByID(CustomerID));
                    loadDataGrid(CustomerID);

                }

            }
            private void setFormKhachHang(KhachHang kh)
            {
                if (kh != null && kh.KhachHangId != Guid.Empty)
                {
                    txtkhachhang.Text = kh.TenKh;
                    //txtdiachi.Text = kh.DiaChiCty;
                    //txtmaso.Text = kh.MaKh;
                }
            }
            private KhachHang getKhachHangByID(Guid khID)
            {
                KhachHang kh = new KhachHang();
                KhachHangService service = new KhachHangService();
                kh = service.GetByKhachHangId(khID);
                return kh;
            }
            private void UpdateRevenue(Revenue Revenue)
            {
                RevenueService service = new RevenueService();
                if (Revenue.Id > 0)
                {
                    service.Update(Revenue);
                }
                else
                {
                    service.Insert(Revenue);
                }
            }


            private void cboHangHoa_InitializeLayout(object sender, InitializeLayoutEventArgs e)
            {
                //cboHangHoa.DisplayMember = "InventoryItemName";
                //cboHangHoa.ValueMember = "InventoryItemID";
                //UltraGridBand band = cboHangHoa.DisplayLayout.Bands[0];
                //band.Columns["InventoryItemID"].Hidden = true;
                //band.Columns["InventoryItemName"].Header.Caption = "Tên Hàng Hóa";
                //band.Columns["InventoryItemName"].Width = 150;
                //band.Columns["InventoryItemName"].CellActivation = Activation.NoEdit;
                //band.Columns["InventoryItemCode"].Header.Caption = "Mã Hàng Hóa";
                //band.Columns["InventoryItemCode"].Width = 150;
                //band.Columns["InventoryItemCode"].CellActivation = Activation.NoEdit;
                //band.Columns["Unit"].Hidden = true;
                //band.Columns["SalePrice"].Hidden = true;
            }

            private void ultraGrid1_CellChange(object sender, CellEventArgs e)
            {
                //If (e.Cell.Column.Key.Equals("Deluxe")) Then
                //If e.Cell.Row.Index() > -1 Then
                //    e.Cell.Row.Cells("HRI NTUserName").Value = UltraDropDown1.SelectedRow.Cells("NTUserName").Value
                //    e.Cell.Row.Cells("HRI EEID").Value = UltraDropDown1.SelectedRow.Cells("EEID").Value
                //    e.Cell.Row.Cells("HRI Manager").Value = UltraDropDown1.SelectedRow.Cells("Manager").Value
                //    e.Cell.Row.Cells("HRI Email").Value = UltraDropDown1.SelectedRow.Cells("Email").Value
                //    e.Cell.Row.Cells("HRI StartDate").Value = UltraDropDown1.SelectedRow.Cells("StartDate").Value
                //    e.Cell.Row.Cells("HRI EndDate").Value = UltraDropDown1.SelectedRow.Cells("EndDate").Value
                //    e.Cell.Row.Cells("HRI CostCenter").Value = UltraDropDown1.SelectedRow.Cells("CostCenterNo").Value

                //End If
                //End If
                //if (e.Cell.Column.Key.Equals("Deluxe") || e.Cell.Column.Key.Equals("DonGia"))
                //{
                //    if (e.Cell.Row.Index > -1)
                //    {
                //        // If ((e.Cell.Row.Cells("Cancel Date").Value Is DBNull.Value) Or (e.Cell.Row.Cells("Cancel Date").Value.ToString() = String.Empty)) Then
                //        //e.Cell.Row.Cells("Status").Value = "Outstanding"
                //        if (e.Cell.Row.Cells["DonGia"].Text != string.Empty & e.Cell.Row.Cells["Deluxe"].Text != string.Empty)
                //        {
                //            e.Cell.Row.Cells["Popular"].Value = Convert.ToDecimal(e.Cell.Row.Cells["DonGia"].Text) * Convert.ToDecimal(e.Cell.Row.Cells["Deluxe"].Text);
                //        }
                //    }
                //}
            }

            private void cmdSearch_Click(object sender, EventArgs e)
            {
                loadDataGrid(CustomerID, txthoadon.Text, Convert.ToInt16(cboYear.Value), Convert.ToInt16(cboMonth.Value));
            }

            private void loadDataGrid(Guid CustomerID, string strhoadon, int year, int month)
            {
                RevenueService dsService = new RevenueService();
                TList<Revenue> listds = dsService.GetAllRevenues(CustomerID,strhoadon, year, month);
                if (listds != null)
                {
                    dsRevenue = listds.ToDataSet(false);
                    ultraGrid1.DataSource = dsRevenue;
                    ultraGrid1.DataBind();
                    loadTongCong(listds);
                }
            }

        
    }
}
